using Cysharp.Threading.Tasks;
using GameFramework.Event;
using GameFramework.Fsm;
using GameFramework.Procedure.Attribute;
using GameFramework.Procedure.Fsm;
using GameFramework.UI;
using GameFramework.UI.FairyGUI;
using GameLogic.Launch;
using GameLogic.UI.Login;

namespace GameLogic.Login
{
    /// <summary>
    /// 登陆流程
    /// </summary>
    [Procedure]
    public sealed class LoginProcedure : AFsmProcedure
    {
        private bool m_Complete;
        
        public override void OnEnter(IFsm fsm)
        {
            base.OnEnter(fsm);
            m_Complete = false;
            EventService.That.Raise(this, LaunchStepUpdatedEvent.Acquire(LaunchStep.OpenLoginForm));
            
            OpenLoginFormAsync().Forget();
        }
        
        private async UniTask OpenLoginFormAsync()
        {
            await UIService.That.OpenUIForm<LoginForm>();

            m_Complete = true;
            EventService.That.Raise(this, LaunchStepUpdatedEvent.Acquire(LaunchStep.OpenLoginForm, 1f));
        }
    }
}